home *** CD-ROM | disk | FTP | other *** search
- Path: shanghai.netgen.com!new-york!erichard
- From: Eric Richard <erichard@netgen.com>
- Newsgroups: comp.lang.c++
- Subject: G++ and global const variable definitions
- Date: Fri, 19 Jan 1996 14:39:16 -0500
- Organization: net.Genesis Corp.
- Message-ID: <Pine.SOL.3.91.960119141858.13188C-100000@new-york>
- NNTP-Posting-Host: new-york.netgen.com
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- X-Sender: erichard@new-york
-
-
- I have a C++ file that contains a single statement: a definition and
- initialization of a global constant variable. It basically looks like this:
-
- extern RWDBPhraseBook const RWDBInformixPhraseBook =
- {
- "", //beginExprOperatorGroup,
- "NoOp", //operatorNoOp,
- ...
- };
-
- When I compile the file and 'nm' the resulting object file, I
- only get this:
-
- [Index] Value Size Type Bind Other Shndx Name
-
- [3] | 0| 0|SECT |LOCL |0 |2 |infphras.o:
- [2] | 0| 0|NOTY |LOCL |0 |2 |infphras.o:gcc2_compiled.
- [1] | 0| 0|FILE |LOCL |0 |ABS |infphras.o:infphras.cpp
-
- If I take out the "extern" and "const", the variable's symbol shows
- up:
-
- [4] | 0| 0|SECT |LOCL |0 |4 |infphras.o:
- [2] | 0| 0|SECT |LOCL |0 |3 |infphras.o:
- [5] | 0| 0|SECT |LOCL |0 |2 |infphras.o:
- [6] | 0| 892|OBJT |GLOB |0 |4 |infphras.o:RWDBInformixPhraseBook
- [3] | 0| 0|NOTY |LOCL |0 |2 |infphras.o:gcc2_compiled.
- [1] | 0| 0|FILE |LOCL |0 |ABS |infphras.o:infphras.cpp
-
-
- According to "Advanced C++ Programming Styles and Idioms":
-
- "Constants may be shared across source files by declaring them
- extern. These declarations can be placed in a commonly included
- header file ... and a SINGLE definition of the value placed in
- a convenient program source file:
-
- ...
- extern const double e = exp( 1.0 );
-
- Any clue what is up here?
-
- -Eric Richard
-
- Eric Richard ----------------------------------- voice: (617) 577-9800
- net.Genesis fax: (617) 577-9850
- 68 Rogers St erichard@netgen.com
- Cambridge, MA 02142 --------------------------- http://www.netgen.com/
-
-
-
-